local sk__zuilun = fk.CreateSkill {

  name = "sk__zuilun",

  tags = { Skill.Compulsory, },

}



sk__zuilun:addEffect(fk.EventPhaseStart, {
  name = "sk__zuilun",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__zuilun.name) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == player and move.moveReason == fk.ReasonDiscard and
        table.find(move.moveInfo, function (info)
          return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
        end) then
          return true
        end
      end
    end, Player.HistoryTurn) == 0 then
      player:drawCards(4, sk__zuilun.name)
    elseif #room:getOtherPlayers(player) > 0 then
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
        "#sk__zuilun1-choose", sk__zuilun.name, false)
      to = room:getPlayerById(to[1])
      to:drawCards(4, sk__zuilun.name)
    end
    if player.dead then return end
    if #room.logic:getEventsOfScope(GameEvent.Recover, 1, function(e)
      local recover = e.data
      return recover.who.id == player.id
    end, Player.HistoryTurn) == 0 then
      room:loseHp(player, 1, sk__zuilun.name)
    elseif #room:getOtherPlayers(player) > 0 then
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
        "#sk__zuilun2-choose", sk__zuilun.name, false)
      to = room:getPlayerById(to[1])
      room:loseHp(to, 1, sk__zuilun.name)
    end
    if player.dead then return end
    if #room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
      local damage = e.data.damageEvent
      return damage and player == damage.from
    end, Player.HistoryTurn) == 0 then
      room:changeMaxHp(player, -1)
    elseif #room:getOtherPlayers(player) > 0 then
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
        "#sk__zuilun3-choose", sk__zuilun.name, false)
      to = room:getPlayerById(to[1])
      room:changeMaxHp(to, -1)
    end
  end,
})

return sk__zuilun